package com.southwind.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.southwind.entity.User;
import com.southwind.mapper.UserMapper;
import com.southwind.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    public static User USER;

    @GetMapping("/login")
    public LoginVO login(User loginForm){
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", loginForm.getUsername());
        User user = this.userMapper.selectOne(queryWrapper);
        if (user == null){
            return new LoginVO(-1,"用户名错误",null);
        }
        if(!user.getPassword().equals(loginForm.getPassword())){
            return new LoginVO(-1,"密码错误",null);
        }
        USER = user;
        return new LoginVO(0,"",user);
    }
}
